﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameLibrary.Settlement
{
    [Serializable]
    public static class SettlementHelper
    {
        #region buildings
        public static BuildingType Road = new BuildingType(
            "Road", 400, SettlementFlags.All);
        public static BuildingType Plant = new BuildingType(
            "Plant", 800, SettlementFlags.Village);
        public static BuildingType Factory = new BuildingType(
            "Factory", 20000, SettlementFlags.City);
        #endregion
        #region building cost base
        public static readonly int BuildingCostBase = 2;
        #endregion
        #region GetProduction
        public static uint GetProduction(Settlement city)
        {
            uint g = 0;
            if (city.VillageNumber > 0)
            {
                foreach (var v in city.GetVillages())
                {
                    v.NextTurn();
                    g += (uint) v.Storage; // collect remaining goods into city
                    v.SetStorage(0);
                }
            }
            g += city.BaseProduction;            
            city.SetIncome(g);
            uint level = 1;
            if (city.Type == SettlementFlags.City) // abstract all production in one settlement in to one building
                level += city.GetBuildingLevel(SettlementHelper.Factory);
            else
                if (city.Type == SettlementFlags.Village)
                    level += city.GetBuildingLevel(SettlementHelper.Plant);
                else
                    throw new NotImplementedException("tempory settlement building not implemented.");
            return city.Income * level;
        }
        #endregion
    }
}
